package filmcity;

import java.util.ArrayList;

public class Customer {
	private String name;
	private ArrayList<Rental> rentalList = new ArrayList<Rental>();

	public Customer(String name) {
		this.name = name;
	}

	public void addRental(Rental arg) {
		rentalList.add(arg);
	}

	public String getName() {
		return name;
	}

	public String statement() {
		String result = reportHeader();
		result += reportAllRentalDetails();
		result += reportFooter(totalRentalAmount(), frequenterPoints());
		return result;
	}

	private String reportAllRentalDetails() {
		String temp = "";
		for (Rental rental : rentalList) {
			temp += reportRental(rental);
		}
		return temp;
	}

	private int frequenterPoints() {
		int frequentRenterPoints = 0;
		for (Rental rental : rentalList) {
			frequentRenterPoints += rental.frequenterPoints();
		}
		return frequentRenterPoints;
	}

	private double totalRentalAmount() {
		double totalAmount = 0;
		for (Rental rental : rentalList) {
			totalAmount += rental.charge();
		}
		return totalAmount;
	}

	private String reportFooter(double totalAmount, int frequentRenterPoints) {
		return "Amount owed is " + totalAmount + "\n" + "You earned "
				+ frequentRenterPoints + " frequent renter points";
	}

	private String reportRental(Rental rental) {
		return "\t" + rental.getMovie().getTitle() + "\t" + rental.charge()
				+ "\n";
	}

	private String reportHeader() {
		String result = "Rental Record for " + getName() + "\n";
		return result;
	}

}
